package com.bawei.lib_common.video

import com.bawei.lib_common.base.BaseApplication
import com.danikula.videocache.HttpProxyCacheServer
import java.io.File


/**
 *作者：lxy
 *功能:
 *时间：2025/6/3
 */
object VideoCacheProxy {

    private var instance: HttpProxyCacheServer? = null
    private fun newProxy(): HttpProxyCacheServer? {
        try {
            return HttpProxyCacheServer.Builder(BaseApplication.instance)
                .cacheDirectory(File(BaseApplication.instance.externalCacheDir, "video-cache"))
                .build()
        } catch (e: Exception) {
            //	java.net.SocketException:socket failed: ENONET (Machine is not on the network)
            e.printStackTrace()
        }
        return null
    }

    fun get(): HttpProxyCacheServer? {
        if (instance == null) {
            synchronized(this) {
                if (instance == null) {
                    instance = newProxy()
                }
            }
        }
        return instance
    }
}